//
//  CZMainViewController.swift
//  微博
//
//  Created by 霸气的刘吉庆 on 16/4/16.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    
    
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = CZTabBar()
    
        //注意这里会循环引用
        tabBar.addButtonClosure = {[weak self] in
            
            let addView = CZComposeView()
//            self?.view.addSubview(addView)
            
            //这里已经是weak self 不会造成循环引用
            addView.show(self)
            
            //设置约束
//            addView.snp_makeConstraints(closure: { (make) -> Void in
//                make.top.leading.trailing.bottom.equalTo((self?.view)!)
//
//            })
            
            
            
            print("加号按钮点击了,弹出控制器")
            //点解了加号,弹出对应的view
        }
        
        
        //将这个tabbar设置给控制器的tabbar
        
        setValue(tabBar, forKey: "tabBar")
        
        
        
        

        // Do any additional setup after loading the view.
        
        //设置跟控制器
        
//        let vc = CZHomeTableViewController()
        
//        vc.title = "首页"
//        vc.tabBarItem.image =
        
        
        //添加子控制器,
        
        addChildViewController(CZHomeTableViewController(), title: "首页", imageName: "tabbar_discover")
        
        addChildViewController(CZMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
    addChildViewController(CZDiscoveryTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(CZProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
        
        
        
        
        
    }
    
   
    
    //定义一个方法用来添加自控制器
    
    func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        
        
        vc.title = title
        
        
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置文字的属性
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        //设置文字的大小
        
//        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(<#T##fontSize: CGFloat##CGFloat#>)], forState: <#T##UIControlState#>)
        
        
        //这个是设置图片下面的字体的大小,也可以要求设计师一起设置
        
//     粗体   vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.boldSystemFontOfSize(15)], forState: .Normal)
        
        
        
        
        
        //注意这里需要添加一个导航控制器
        
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

 

}
